﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test_edit.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Certificate.test_edit" %>

<%@ Import Namespace="DataAccess" %>
<%@ Import Namespace="System.Linq" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        int id = int.Parse(Request.QueryString["id"]);

        var get_test = new TblTestController().FetchAll().Where(x => x.TestId == id).Single();
    %>
    <div class="w3-padding w3-row">
        <label class="w3-quarter">Chọn Bằng</label>
        <select id="ddl_edit_certificate" style="width: 50%; padding: 0.5%; color: black">
            <%foreach (TblCertificate cer in new TblCertificateController().FetchAll())
              { %>
            <option <%if(cer.CerId==get_test.TestCertificate) {%>selected="selected" <%} %>value="<%=cer.CerId %>"><%=cer.CerTitle %></option>
            <%} %>
        </select>
    </div>
    <div class="w3-padding w3-row">
        <label class="w3-quarter">Tên bài</label>
        <input type="text" id="edit_name" required="required" value="<%=get_test.TestTitle %>" autofocus="autofocus" style="width: 50%; padding: 0.5%; color: black" />
    </div>
    <div class="w3-padding w3-row">
        <label class="w3-quarter">Thời gian làm bài (Phút)</label>
        <input type="number" id="edit_time" step="5" min="1" value="<%=get_test.TestTime %>" required="required" autofocus="autofocus" style="width: 50%; padding: 0.5%; color: black" />
    </div>
    <div class="w3-row w3-padding">
        <label class="w3-quarter">Loại bài</label>
        <div class="radio w3-half">
            <%
                if (get_test.TestExam == false)
                {
            %>
            <input onclick="document.getElementById('d-day-edit').style.display = 'none'" type="radio" checked="checked" name="test-type-edit" value="0" id="thuong-edit" /><label for="thuong-edit">Thường</label>&nbsp;
            <%}
                else
                { %>
            <input onclick="document.getElementById('d-day-edit').style.display = 'none'" type="radio" name="test-type-edit" value="0" id="thuong-edit" /><label for="thuong-edit">Thường</label>&nbsp;
            <%}
                if (get_test.TestExam == true)
                {%>
            <input onclick="document.getElementById('d-day-edit').style.display = 'block'" type="radio" checked="checked" name="test-type-edit" value="1" id="thikt-edit" /><label for="thikt-edit">Thi/Kiểm tra</label>
            <%}
                else
                { %>
            <input onclick="document.getElementById('d-day-edit').style.display = 'block'" type="radio" name="test-type-edit" value="1" id="thikt-edit" /><label for="thikt-edit">Thi/Kiểm tra</label>
            <%} %>
        </div>
    </div>
    <div id="d-day-edit" class="w3-padding w3-row w3-animate-left" <%if (get_test.TestExam == false)
                                                                     { %>
        style="display: none;" <%} %>>
        <%
            string time = "";
            if (get_test.TestStart != null)
            {
                string day = "", month = "", hour = "", minute = "", sec = "";
                var get_day = DateTime.Parse(get_test.TestStart.ToString()).Day;
                if (get_day < 10)
                    day = "0" + get_day;
                else
                    day = get_day.ToString();
                var get_month = DateTime.Parse(get_test.TestStart.ToString()).Month;
                if (get_month < 10)
                    month = "0" + get_month;
                else
                    month = get_month.ToString();
                var get_hour = DateTime.Parse(get_test.TestStart.ToString()).Hour;
                if (get_hour < 10)
                    hour = "0" + get_hour;
                else
                    hour = get_hour.ToString();
                var get_minute = DateTime.Parse(get_test.TestStart.ToString()).Minute;
                if (get_minute < 10)
                    minute = "0" + get_minute;
                else
                    minute = get_minute.ToString();
                var get_sec = DateTime.Parse(get_test.TestStart.ToString()).Second;
                if (get_sec < 10)
                    sec = "0" + get_sec;
                else
                    sec = get_sec.ToString();
                time = DateTime.Parse(get_test.TestStart.ToString()).Year.ToString() + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + sec;
            }
        %>
        <label class="w3-quarter">Ngày mở bài </label>
        <input type="datetime-local" id="edit_start" value="<%=time %>" style="width: 50%; padding: 0.5%; color: black" />
    </div>
    <div class="w3-row w3-padding">
        <label class="w3-quarter">Cấp quyền</label>
        <div class="checkbox w3-half">
            <%
                var get_level = new TblUserRoleController().FetchAll().ToList();
                string[] level = new string[get_test.TestLevel.Split(',').Length];
                level = get_test.TestLevel.Split(',');

                for (int i = 1; i <= get_level.Count; i++)
                {
                    int check = 0;
                    for (int j = 0; j < get_test.TestLevel.Split(',').Length - 1; j++)
                    {
                        if (int.Parse(level[j]) == get_level[i - 1].RoleId)
                            check = 1;
                    }
            %>
            <input type="checkbox" value="<%=get_level[i - 1].RoleId%>" <%if (check == 1)
                                                                          { %>checked="checked"
                <%} %> id="edit_quyen<%=i%>" class="edit_user_level" /><label for="edit_quyen<%=i%>"><%=get_level[i - 1].RoleName%></label>&nbsp;&nbsp;&nbsp;&nbsp;
                  <%} %>
        </div>
    </div>
    <div class="w3-row w3-padding">
        <label class="w3-quarter">Đóng/Mở bài</label>
        <div class="w3-half w3-xlarge">
            <%int active = 0;
              if (get_test.TestActive == true)
                  active = 1; %>
            <div id="edit_active" class="w3-hide"><%=active %></div>
            <%if (active == 0)
              {%>
            <i class="edit-on fa fa-toggle-on fa-rotate-180 w3-text-red w3-animate-opacity off"></i>
            <%}
              else
              { %>
            <i class="edit-on fa fa-toggle-on w3-text-white w3-animate-opacity "></i>
            <%} %>
        </div>
    </div>
    <div class="w3-row w3-padding w3-center">
        <a class="edited w3-btn w3-teal w3-border w3-border-white"><i class="fa fa-save"></i>&nbsp;Lưu</a>
    </div>
</body>
</html>
